using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bomb : MonoBehaviour
{
    public Collider2D ObstacleArea;
    public float reset_time;
    void Start()
    {
        reset_time = 1f;
        ObstacleArea = GameObject.Find("area").GetComponent<BoxCollider2D>();
        RandomPosition();
    }
    private void Update()
    {
        if(reset_time > 0)
        {
            reset_time -= Time.deltaTime;
        }
        else
        {
            RandomPosition();
        }
    }
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Food" || collision.gameObject.tag == "Obstacle")
        {
            RandomPosition();
        }

    }



    public void RandomPosition()
    {
        reset_time = 1f;
        transform.position = new Vector2(Random.Range(ObstacleArea.bounds.min.x, ObstacleArea.bounds.max.x), Random.Range(ObstacleArea.bounds.min.y, ObstacleArea.bounds.max.y));
    }
}
